package com.ksu.manager.dao.ibatisImpl;

import java.util.List;

import org.mybatis.spring.support.SqlSessionDaoSupport;

import com.ksu.manager.dao.ITypeItemDAO;
import com.ksu.manager.model.TypeItem;

public class TypeItemDAOImpl extends SqlSessionDaoSupport implements ITypeItemDAO {

	
	@SuppressWarnings({ "unchecked"})
	public List<TypeItem> queryList(TypeItem typeItem) {
		List<TypeItem> typeItemList = null;
		try {
		    if(typeItem==null){
		    	typeItem = new TypeItem();
		    }
		    typeItemList = (List<TypeItem>)this.getSqlSession().selectList("typeItem.select",typeItem);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return typeItemList;
	}

	public void create(TypeItem typeItem) {
		try {
			this.getSqlSession().insert("typeItem.insert",typeItem);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public void delete(TypeItem typeItem) {
		try {
			this.getSqlSession().delete("typeItem.delete",typeItem);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	@SuppressWarnings("unchecked")
	public TypeItem getTypeItemById(TypeItem typeItem) {
		if(typeItem.getId() > 0){
			List<TypeItem> typeItemList = (List<TypeItem>)this.getSqlSession().selectList("typeItem.select",typeItem);
			typeItem = typeItemList.get(0);
			return typeItem;
		}else{
		    return null;	
		}
	}

	
	public void update(TypeItem typeItem) {
		try {
		    this.getSqlSession().update("typeItem.update",typeItem);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
